package server;

import java.net.*;
import java.util.Calendar;
import java.math.BigInteger;

public class Server implements Runnable {

	private ServerSocket serverSocket;
	private Calendar votingStartDate;
	private Calendar votingEndDate;
	private BigInteger[] publicKey;
	private BigInteger[] privateKey;
	private int maxnumberOfVoters;

	public Server() throws Exception {
		this.votingStartDate = null;
		this.votingEndDate = null;
		this.publicKey = null;
		this.privateKey = null;
		this.maxnumberOfVoters = 30;
		this.serverSocket = new ServerSocket(4444);
		System.out.println("Server started");
		this.run();
	}

	public Calendar getVotingStartDate() {
		return votingStartDate;
	}

	public void setVotingStartDate(Calendar votingStartDate) {
		this.votingStartDate = votingStartDate;
	}

	public Calendar getVotingEndDate() {
		return votingEndDate;
	}

	public void setVotingEndDate(Calendar votingEndDate) {
		this.votingEndDate = votingEndDate;
	}

	public BigInteger[] getPublicKey() {
		return publicKey;
	}

	public void setPublicKey(BigInteger[] publicKey) {
		this.publicKey = publicKey;
	}

	public BigInteger[] getPrivateKey() {
		return privateKey;
	}

	public void setPrivateKey(BigInteger[] privateKey) {
		this.privateKey = privateKey;
	}

	public int getMaxNumberOfVoters() {
		return maxnumberOfVoters;
	}

	public void run() {
		while (true) {
			try {
				Socket connectionSocket = serverSocket.accept();
				ServerThread s = new ServerThread(this, connectionSocket);
				s.start();
			} catch (Exception e) {
			}
		}
	}

	public static void main(String[] args) throws Exception {
		new Server();
	}
}
